package com.sky.mapper;

import com.sky.entity.AddressBook;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface AddressBookMapper {

    @Select("select * from address_book")
    List<AddressBook> selectAll();

    @Select("select * from address_book where id = #{id}")
    AddressBook selectById(Long id);

    void update(AddressBook addressBook);

    @Delete("delete from address_book where id = #{id}")
    void delete(Long id);

    void setIsNotDefault(AddressBook addressBook);
    @Insert("INSERT INTO address_book (user_id, consignee, sex, phone, province_code, province_name, " +
            "city_code, city_name, district_code, district_name, detail, label, is_default) " +
            "VALUES (#{userId}, #{consignee}, #{sex}, #{phone}, #{provinceCode}, #{provinceName}, " +
            "#{cityCode}, #{cityName}, #{districtCode}, #{districtName}, #{detail}, #{label}, #{isDefault})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    void insert(AddressBook addressBook);

    AddressBook queryByCondition(AddressBook addressBook);

    @Select("select * from address_book where id = #{addressBookId}")
    AddressBook getById(Long addressBookId);
}
